use std::fmt::Display;

#[derive(Debug)]
pub struct User {
    pub username: String,
    pub password: String,
    pub role: Role,
}
#[derive(Debug)]
pub enum Role {
    Admin,
    Normal,
}

// 首先为 Role 实现 Display，这样才能在 User 的 Display 中使用
impl Display for Role {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Role::Admin => write!(f, "Admin"),
            Role::Normal => write!(f, "Normal"),
        }
    }
}

// 然后为 User 实现 Display
impl Display for User {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        // 直接使用各个字段的 Display 实现来格式化
        write!(
            f,
            "User {{ username: '{}', password: '{}', role: {} }}",
            self.username, self.password, self.role
        )
    }
}